package com.aacar.op.service.security;

import com.aacar.op.entity.user.User;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * Shiro Authentication对象，使得Subject除了携带用户的登录名外还可以携带更多信息.
 *
 * @author Gongle
 */
public class ShiroUser implements Serializable {
    private static final long serialVersionUID = -1373760761780840081L;
    private Long id;
    private String loginName;
    private String avatarUrl;
    private String name;
    private String orgName;
    private String orgCode;
    private String orgId;
    private String host;
    private String mobile;
    private String email;
    private String permissions;  //权限表达式  ,多个","分隔
    public ShiroUser() {
    }

    public ShiroUser(User user) {
        this.id = user.getId();
        this.loginName = user.getLoginName();
        this.name = user.getName();
        this.mobile=user.getMobile();
        this.email=user.getMobile();
        this.permissions=user.getPermissions();
    }

    public List<String> getPermissionList() {
        List<String> list = Lists.newArrayList();
        if (StringUtils.isNotBlank(this.permissions)) {
            String[] perArr = StringUtils.split(this.permissions, ",");
            list = Lists.newArrayList(perArr);
        }
        return list;
    }
    /**
     * 本函数输出将作为默认的<shiro:principal/>输出.
     */
    @Override
    public String toString() {
        return name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOrgName() {
        return orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }

    public String getOrgCode() {
        return orgCode;
    }

    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }

    public String getOrgId() {
        return orgId;
    }

    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPermissions() {
        return permissions;
    }

    public void setPermissions(String permissions) {
        this.permissions = permissions;
    }
}